﻿Public Class frmConsultaCesta
    Dim objCesta As New CLSCestas

    Private Sub dgvCestas_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvCestas.CellDoubleClick
        frmCadPedidos.txtCodCesta.Text = Me.dgvCestas.CurrentRow.Cells(0).Value
        frmCadPedidos.txtNomCesta.Text = Me.dgvCestas.CurrentRow.Cells(1).Value
        frmCadPedidos.txtValorUniCesta.Text = Me.dgvCestas.CurrentRow.Cells(2).Value
        frmCadPedidos.txtQtdCestaPedido.Focus()
        Me.Close()

    End Sub

    Private Sub frmConsultaCesta_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgvCestas.DataSource = objCesta.LocalizarPorNome("")
    End Sub

    'Seleccionar uma linha de acordo com um número (ID)

    Private Function getDataGridViewIndex(ByVal id As Integer) As Integer
        For Each row As DataGridViewRow In Me.dgvCestas.Rows
            If Not row.IsNewRow Then
                If row.Cells(0).Value = id Then
                    Return row.Index
                End If
            End If

        Next
        Return 0
    End Function



    Private Sub dgvCestas_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvCestas.CellContentClick

        ' Alterações na coluna 1 
        With Me.dgvCestas.Columns(1)

            ' Altera o alinhamento das células para o centro  
            .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            ' Altera o alinhamento da header para o centro  
            .HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        End With
    End Sub
End Class